#include "graph.h"
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
namespace PEANEEVALL_KALAA{
  using namespace std;
  vector<vector<int>> Lnk, What, To, Son; vector<int> Fa, From;
  int n = 1;
  int DFS_0(int id, int fa){
    if(int c = Color(); c > 1) return Move(LastRoad(), c), c;
    Lnk.emplace_back(), What.emplace_back(), To.emplace_back(), Son.emplace_back();
    Fa.push_back(fa), From.push_back(LastRoad());
    if(fa >= 0) Son[fa].push_back(id);
    for(int i = 1; i <= NumberOfRoads(); i++) if(i != From[id]){
      if(int x = (Move(i, 2), DFS_0(n++, id)); x == 2)
        n--, Lnk[id].push_back(i), What[id].push_back(0);
      else if(x == 1) To[id].push_back(i); else n--;
    }
    if(id) Move(From[id], 3);
    return 1;
  }
  void DFS(int id, int k){
    for(int i = 0; i < (int)To [id].size(); i++) Move(To[id][i], 1 + id / k % 3), DFS(Son[id][i], k);
    for(int i = 0; i < (int)Lnk[id].size(); i++){
      Move(Lnk[id][i], 1 + id / k % 3); int c = Color(); What[id][i] += (c - 1) * k;
      Move(LastRoad(), c);
    }
    if(id) Move(From[id], Color());
  }
  constexpr int MAXN = 205;
  int F[MAXN][MAXN], Cnt[MAXN];
  void link(int x, int y){F[x][y] = F[y][x] = min(F[x][y], 1);}
  void answer(int m){
    memset(F, 0x3F, sizeof(F));
    for(int i = 0; i < n; i++) F[i][i] = 0;
    for(int i = 0; i < n; i++){
      if(i) link(i, Fa[i]);
      for(int nxt: What[i]) link(i, nxt);
    }
    for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++)
      F[i][j] = min(F[i][j], F[i][k] + F[k][j]);
    for(int i = 0; i < n; i++) for(int j = i; j < n; j++) if(F[i][j] <= n) Cnt[F[i][j]]++;
    for(int i = 1; i <= m; i++) Answer(i, Cnt[i]);
    m = 0;
    for(int i = 0; i < n; i++) m += What[i].size();
  }
}
void Inspect(int m){
  using namespace PEANEEVALL_KALAA;
  DFS_0(0, -1);
  for(int k = 1; true; k *= 3) if(DFS(0, k), k * 3 >= n) break;
  answer(m);
  // for(int i = 0; i < n; i++){
  //   if(i) cerr << i << ' ' << Fa[i] << endl;
  //   for(int nxt: What[i]) cerr << i << ' ' << nxt << endl;
  // }
}
